Live
Black Hat USADark ReadingBlack Hat AsiaAI BusinessShahed-killing interceptor drones may look simple, but building them to keep up with the threat isn't easyBusiness InsiderDetecting Complex Money Laundering Patterns with Incremental and Distributed Graph ModelingarXivUQ-SHRED: uncertainty quantification of shallow recurrent decoder networks for sparse sensing via engressionarXivJetPrism: diagnosing convergence for generative simulation and inverse problems in nuclear physicsarXivSECURE: Stable Early Collision Understanding via Robust Embeddings in Autonomous DrivingarXivDySCo: Dynamic Semantic Compression for Effective Long-term Time Series ForecastingarXivModel Merging via Data-Free Covariance EstimationarXivMassively Parallel Exact Inference for Hawkes ProcessesarXivEfficient and Principled Scientific Discovery through Bayesian Optimization: A TutorialarXivSven: Singular Value Descent as a Computationally Efficient Natural Gradient MethodarXivAn Online Machine Learning Multi-resolution Optimization Framework for Energy System Design Limit of Performance AnalysisarXivForecasting Supply Chain Disruptions with Foresight LearningarXivBlack Hat USADark ReadingBlack Hat AsiaAI BusinessShahed-killing interceptor drones may look simple, but building them to keep up with the threat isn't easyBusiness InsiderDetecting Complex Money Laundering Patterns with Incremental and Distributed Graph ModelingarXivUQ-SHRED: uncertainty quantification of shallow recurrent decoder networks for sparse sensing via engressionarXivJetPrism: diagnosing convergence for generative simulation and inverse problems in nuclear physicsarXivSECURE: Stable Early Collision Understanding via Robust Embeddings in Autonomous DrivingarXivDySCo: Dynamic Semantic Compression for Effective Long-term Time Series ForecastingarXivModel Merging via Data-Free Covariance EstimationarXivMassively Parallel Exact Inference for Hawkes ProcessesarXivEfficient and Principled Scientific Discovery through Bayesian Optimization: A TutorialarXivSven: Singular Value Descent as a Computationally Efficient Natural Gradient MethodarXivAn Online Machine Learning Multi-resolution Optimization Framework for Energy System Design Limit of Performance AnalysisarXivForecasting Supply Chain Disruptions with Foresight LearningarXiv
AI NEWS HUBbyEIGENVECTOREigenvector

Number Operations (Sum, Count, Reverse) Using Loop in Java

DEV Communityby VidyaApril 1, 20261 min read1 views
Source Quiz

<ol> <li>Sum of Digits</li> </ol> <p><strong>java</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight java"><code><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Main</span> <span class="o">{</span> <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="nc">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="o">{</span> <span class="kt">int</span> <span class="n">num</span> <span class="o">=</span> <span class="mi">1234</span><span class="o">,</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="k">while</span> <

  • Sum of Digits

java

public class Main {  public static void main(String[] args) {  int num = 1234, sum = 0;

while (num > 0) { sum += num % 10; num =num/ 10; }

System.out.println("Sum = " + sum); } }`

Enter fullscreen mode

Exit fullscreen mode

output

  1. Count of Digits

java

public class Main {  public static void main(String[] args) {  int num = 1234, count = 0;

while (num > 0) { num =num/ 10; count++; }

System.out.println("Count = " + count); } }`

Enter fullscreen mode

Exit fullscreen mode

output

  1. Reverse a Number

public class Main {  public static void main(String[] args) {  int num = 1234, rev = 0;

while (num > 0) { rev = rev * 10 + num % 10; num =num/ 10; }*

System.out.println("Reverse = " + rev); } }`

Enter fullscreen mode

Exit fullscreen mode

output

Was this article helpful?

Sign in to highlight and annotate this article

AI
Ask AI about this article
Powered by Eigenvector · full article context loaded
Ready

Conversation starters

Ask anything about this article…

Daily AI Digest

Get the top 5 AI stories delivered to your inbox every morning.

Knowledge Map

Knowledge Map
TopicsEntitiesSource
Number Oper…DEV Communi…

Connected Articles — Knowledge Graph

This article is connected to other articles through shared AI topics and tags.

Knowledge Graph100 articles · 289 connections
Scroll to zoom · drag to pan · click to open

Discussion

Sign in to join the discussion

No comments yet — be the first to share your thoughts!

More in Products