+ 4
Can anyone help me with my code?
https://code.sololearn.com/cU97fzpo5b2v/?ref=app I want numbers on descending order (e.g.20,19,18 ) (I will appreciate it if anyone can help me)
18 Respuestas
+ 2
Yes, with the help of "Ipang"( sololearn's user)
Here is the thing i want to make something like this:
2019
Happy birthday! You are 20
2018
Happy birthday! You are 19
2017
Happy birthday! You are 18 .......
+ 2
Subhojit Sikdar ,thank you very much 👍
+ 1
Mélina first of all thank you for your help. The problem is that if i make +1 to -1 my code starts from -1 and it ends to the number -1 e.g. if my number is 5 the output will be:
-1
0
1
2
3
But i want
5
4
3
2
1
+ 1
MélinaThanks 👍 anyway because my code looks much better now
(despite i am still fixing it)
+ 1
Mélina Wow thank you!!!!!!!!!!!!!!!!!👍👍👍👍👍👍👍👍👍👍
+ 1
mport java.util.Scanner;
// Compiler version JDK 11.0.2
class Dcoder
{
public static void main(String args[])
{
int arr[] = new int [8];
Scanner sc = new Scanner(System.in);
System.out.print("Enter 8 Digits (Separate with space):");
for(int i = 0; i < arr.length; i++)
{
arr[i] = sc.nextInt();
}
int temp = 0;
for(int i = 0; i < arr.length; i++)
{
for(int j = i + 1; j < arr.length; j++)
{
if (arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
}
}
Guys please help me with this because I don't really understand the flow of my code. Please help
+ 1
Subhojit Sikdar, first of all thank you for your help. Secondly could you please explain this to me a little more?
0
https://code.sololearn.com/cJuG6445Lf5R/?ref=app
Try slicing them
0
This is called Slicing in Python which slices a string an example ...
2 0 1 9
Has 4 digits
We have to consider this as a string then number it
2 0 1 9
0 1 2 3
Then printing str[2:1000]
It will start printing char starting from 2 which means 1 and I set the stopping number to 1000 because I think it's undefined and printing the string will end after 1000 characters as defined ..
formula:
string[startnumber : endnumber]
Suppose I am subhojit
slice it and display subho only
str="subhojit"
Print(str[0:4])
0
Glad I could help! 😉