Advertisement
Guest User

Somando 30 números usando o While

a guest
Feb 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package whilesistema;
  2. import java.util.Scanner;
  3. /**
  4.  *
  5.  * @author gabriel.medeiros
  6.  */
  7. public class WhileSistema {
  8.  
  9.     /**
  10.      * @param args the command line arguments
  11.      */
  12.     public static void main(String[] args) {
  13.         // TODO code application logic here
  14.         //declarando variáveis
  15.         int n1,r = 0,cont = 1;
  16.         Scanner xuxa = new Scanner (System.in);
  17.         //fazendo while como laço de repetição
  18.         while (cont <= 30){
  19.             System.out.println("Digite um número: ");
  20.             n1 = xuxa.nextInt();
  21.             r = n1+cont;
  22.             cont ++;
  23.         }
  24.         //fim do laço
  25.         //mostrando o resultado
  26.         System.out.println("O total foi de: " + r);
  27.    }    // fim resultado
  28. } //fim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement