Professional Documents
Culture Documents
int count = 0;
if (nums[i] ==9) {
count++;
return count;
NUMAR INVERSAT:
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
int n, reverse = 0;
System.out.println("Enter an integer to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while(n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println("Reverse of the number is " + reverse);
}
}
int x = 10;
add 1, then use the x is 11; y
++x int y;
value is 11
y = ++x ;
int x = 10;
use the value, then x is 9; y
x-- int y;
subtract 1 is 10
y = x-- ;
int x = 10;
subtract 1, then use x is 9; y
--x int y;
the value is 9
y = --x ;
import java.lang.*;
import java.util.*;
class Main {
public static void main(String[] args) {
String str;
int sum = 0;
Scanner in=new Scanner(System.in);
System.out.println("Introduceti IBAN : !");
str = in.nextLine();
String str1 =str.substring(0,4);
String str2 =str.substring(4);
String str3 =str2+str1;
System.out.println(str3);
String str4 = str.replaceAll("A", "10").replaceAll("B", "11").replaceAll("C",
"12").replaceAll("D", "13").replaceAll("E", "14").replaceAll("F",
"15").replaceAll("G", "16").replaceAll("H", "17").replaceAll("I",
"18").replaceAll("J", "19").replaceAll("K", "20").replaceAll("L",
"21").replaceAll("M", "22").replaceAll("N", "23").replaceAll("O",
"24").replaceAll("P", "25").replaceAll("Q", "26").replaceAll("R",
"27").replaceAll("S", "28").replaceAll("T", "29").replaceAll("U",
"30").replaceAll("V", "31").replaceAll("W", "32").replaceAll("X",
"33").replaceAll("Y", "34").replaceAll("Z", "35");
System.out.println(str4);
for (int i = 0; i < str4.length(); i++) {
if(Character.isDigit(str4.charAt(i)))
sum=sum+Character.getNumericValue(str4.charAt(i));
}
System.out.println("Sum of all the digit present in String : "+sum);
}
}
PASSWORD MAKER
import
java.util.Scan
ner;
class PasswordMaker {
String getPassword() {
String output = this.fName.substring(this.fName.length() -
this.age % 3);
return output;
}
System.out.println("Diana");
System.out.print("*");
}
System.out.println(); // Go to next line
TABLA INMULTIRII
import java.util.Scanner;
int n,c;
System.out.println("Introduceti un numar");
n=in.nextInt();
import java.util.Scanner;
int a, b, c, d;
a=in.nextInt();
b=in.nextInt();
for(c=a;c<=b;c++){
for(d=a;d<=10;d++){
int a = 0;
int b = 11;
int s=0;
s=s+i;}
AFISEAZA ALFABETUL
public class Main{
char t;
for (t = 'a'; t <= 'z'; t++) // For upper case use 'A' and 'Z'
System.out.println(t);
REVERSE A STRING
import java.util.Scanner;
original = in.nextLine();
import java.util.Scanner;
int n;
int sum=0;
while (true) {
n = sc.nextInt();
if (n < 0.0) {
break;
sum += n;
import java.util.*;
while (!sc.hasNext("exit")) {
System.out.println(
import java.util.Scanner;
class ReverseNumber
{
public static void main(String args[])
{
int n, reverse = 0;
System.out.println("Enter an integer to
reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while(n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
largest = num;
System.out.println(largest);
NUMBER OF DIGITS
// num = num/10
num /= 10;
++count;
===============================================================
===============
SUM OF DIGITS
import java.util.Scanner;
int n;
int sum = 0;
System.out.println("Introdu nr");
n = console.nextInt();
for(sum=0;n!=0;n/=10)
sum+=n%10;}
System.out.println(sum);
}
==================================================================
====